package com.control;

import java.sql.CallableStatement;
import java.sql.SQLException;

import com.db.DBConnect;
import com.model.Serve;

public class ServeControl {
		
	/**
	 * 插入服务
	 * @param serve
	 * @return
	 */
	public boolean insertServe(Serve serve) {
		DBConnect dbc = new DBConnect();
		/*
		String sql1 = "insert into serve(fault_id, admin_id, serve_des, serve_time) values(" +
				""+ serve.getFault_id() +", "+ serve.getAdmin_id() +", '"+ serve.getServe_des() +"', " +
				"getDate() )";
		String sql2 = "update fault set fault_deal = 'true' where fault_id = "+ serve.getFault_id() +"";
		*/
		String sql = "{call insertServe("+ serve.getFault_id() +", "+ serve.getAdmin_id() +", '"+ serve.getServe_des() +"')}";
		try {
			CallableStatement stmt = dbc.getConnection().prepareCall(sql);
			stmt.execute();
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("插入serve失败！");
			return false;
		} finally {
			dbc.close();	
		}
	}
	
	/**
	 * 更新服务
	 * @param serve
	 * @return
	 * @throws SQLException
	 */
	public boolean updateServe(Serve serve) throws SQLException{
		DBConnect dbc=new DBConnect();
		String sql="{call updateServe("+serve.getAdmin_id()+"," +
				"'"+serve.getServe_des()+"',"+serve.getFault_id()+")}";
		/*String sql="update serve set admin_id = "+ serve.getAdmin_id() +", "+
					"serve_des = '" + serve.getServe_des() +"', "+
					"serve_time = getDate() "+
					"where serve_id = (select serve_id from serve where fault_id = "+ serve.getFault_id() +" )";
		*/
		try{
			CallableStatement stmt = dbc.getConnection().prepareCall(sql); 
			stmt.execute();
			return true;
		}finally{
			dbc.close();
		}
	} 
	
}
